package sentinel.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import spring.cloud.Utils.R;

/**
 * @author cyt
 * @create 2020-06-06 7:21
 */
@RestController
public class limitController {
    @GetMapping("/byResource")
    @SentinelResource(value = "byResource", blockHandler = "handleException")
    public R byResource() {
        return R.ok().data("byResource", "ok");
    }

    public R handleException(BlockException exception) {
        return R.error().data("byResource exception", "error");
    }

    @GetMapping("/rateLimit/byUrl")
    @SentinelResource(value = "byUrl")
    public R byUrl() {
        return R.ok().data("ByUrl", "ok");
    }


}